package com.kotlin.myapplication.mvp.ui.main.adapter

import android.view.ViewGroup
import androidx.annotation.Nullable
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter

/**
 *@lil
 *@创建时间 2019/11/4 17:30
 *@描述
 */

class ViewPagerAdapter(fm: FragmentManager, mFragmentList: ArrayList<Fragment>, title: Array<String>?) : FragmentStatePagerAdapter(fm) {

    var fragmentList = ArrayList<Fragment>()
    var array: Array<String>? = null

    init {
        fragmentList = mFragmentList
        array = title
    }

    override fun getItem(p0: Int): Fragment {
        return fragmentList!!.get(p0)
    }

    override fun getCount(): Int {
        if (null == fragmentList) {
            return 0
        }
        return fragmentList!!.size
    }

    @Nullable
    override fun getPageTitle(position: Int): CharSequence? {
        if (null == array)
            return null
        return array!![position]
    }

    /**
     * 每次更新完成ViewPager的内容后，调用该接口，此处复写主要是为了让导航按钮上层的覆盖层能够动态的移动
     */
    override fun finishUpdate(container: ViewGroup) {
        super.finishUpdate(container)//这句话要放在最前面，否则会报错
    }
}